from course import models
from rest_framework import serializers

# 被嵌套的分类序列化
class CategorySer(serializers.ModelSerializer):
    class Meta:
        model = models.Category
        fields = ["id","cname"]

# 分类的序列化
class CategorySerializer(serializers.ModelSerializer):
    # 嵌套序列化  children这个字段是在定义模型的时候 通过related_name定义的 如果不定义使用 category_set
    children = CategorySer(many=True)
    class Meta:
        model = models.Category
        fields = '__all__'